package com.lxd.controller;

import com.lxd.entity.ClubRequest;
import com.lxd.entity.query.ClubQuery;
import com.lxd.entity.po.Club;
import com.lxd.entity.vo.ResponseVO;
import com.lxd.service.ClubService;
import org.springframework.web.bind.annotation.RequestBody;
import org.springframework.web.bind.annotation.RequestMapping;
import org.springframework.web.bind.annotation.RequestMethod;
import org.springframework.web.bind.annotation.RestController;

import javax.annotation.Resource;
import java.util.List;

/**
 * Controller
 */
@RestController("clubController")
@RequestMapping("/club")
public class ClubController extends ABaseController {

    @Resource
    private ClubService clubService;

    /**
     * 根据条件分页查询
     */
    @RequestMapping("/loadDataList")
    public ResponseVO loadDataList(ClubQuery query) {
        query.setStatus(1);
        return getSuccessResponseVO(clubService.findListByPage(query));
    }

    /**
     * 根据条件分页查询
     */
    @RequestMapping("/admin/loadDataList")
    public ResponseVO AdminloadDataList(ClubQuery query) {
        return getSuccessResponseVO(clubService.findListByPage2(query));
    }

    /**
     * 新增
     */
    @RequestMapping("/add")
    public ResponseVO add(@RequestBody ClubRequest clubRequest) {
        clubService.add(clubRequest);
        return getSuccessResponseVO(null);
    }

    /**
     * 批量新增
     */
    @RequestMapping("/addBatch")
    public ResponseVO addBatch(@RequestBody List<Club> listBean) {
        clubService.addBatch(listBean);
        return getSuccessResponseVO(null);
    }

    /**
     * 批量新增/修改
     */
    @RequestMapping("/addOrUpdateBatch")
    public ResponseVO addOrUpdateBatch(@RequestBody List<Club> listBean) {
        clubService.addBatch(listBean);
        return getSuccessResponseVO(null);
    }

    /**
     * 根据Id查询对象
     */
    @RequestMapping("/getClubById")
    public ResponseVO getClubById(Long id) {
        return getSuccessResponseVO(clubService.getClubById(id));
    }

    /**
     * 根据Id修改对象
     */
    @RequestMapping("/updateClubById")
    public ResponseVO updateClubById(@RequestBody ClubRequest club) {
        clubService.updateClubById(club, club.getId());
        return getSuccessResponseVO(null);
    }

    /**
     * 根据Id删除
     */
    @RequestMapping("/deleteClubById")
    public ResponseVO deleteClubById(@RequestBody ClubRequest club) {
        Long id = club.getId();
        clubService.deleteClubById(id);
        return getSuccessResponseVO(null);
    }

    /**
     * 根据Id查询对象，返回身份为社长的社团信息
     */
    @RequestMapping("/getMyClub")
    public ResponseVO getMyClubByUserId(Long userId) {
        return getSuccessResponseVO(clubService.getMyClubByUserId(userId));
    }

    /**
     * 根据社团ID获取成员信息
     */
    @RequestMapping(value = "/getMembersByClubId", method = RequestMethod.GET)
    public ResponseVO getMembersByClubId(Long clubId) {
        return getSuccessResponseVO(clubService.getMembersByClubId(clubId));
    }

    /**
     * 启用/禁用社团
     */
    @RequestMapping("/toggleStatus")
    public ResponseVO toggleStatus(@RequestBody Club club) {
        Long id = club.getId();
        Integer status = club.getStatus();
        clubService.toggleStatus(id, status);
        return getSuccessResponseVO(null);
    }

    @RequestMapping("/totalCount")
    public ResponseVO totalCount() {
        Integer count = clubService.getTotalCount();
        return getSuccessResponseVO(count);
    }


}